import scrapy

'''
setting.py 中关闭君子协定
# ROBOTSTXT_OBEY = True
'''
class TcSpider(scrapy.Spider):
    name = "tc"
    allowed_domains = ["https://bj.58.com/sou/?key=%E5%89%8D%E7%AB%AF%E5%BC%80%E5%8F%91"]
    start_urls = ["https://bj.58.com/sou/?key=%E5%89%8D%E7%AB%AF%E5%BC%80%E5%8F%91"]

    def parse(self, response):
        print('----------tc开始----------')
        content = response.text
        # print(content)
        with open('tc.html','w',encoding='utf-8') as fp:
            fp.write(content)

        span = response.xpath('//*[@id="filter"]/div[1]/a[1]/span')[0]
        print('=======================')
        # <span>全部</span>
        print(span.extract())
        print('----------tc结束----------')
